package Store;

import java.util.ArrayList;
import java.util.Date;

public class Order {
	private String orderID;
	private Customer customer;
	private String customerID;
	private Address billingAddress;
	private String billingAdrID;
	private Address shippingAddress;
	private String shippingAdrID;
	private Date orderDate;
	private Date shipDate;
	private Float total;
	private Float tax;
	private Float subtotal;
	private String status;
	private Float discountPercent;
	private Float discountAmount;
	private Boolean submittedStatus;
	private Boolean sameBillShipAdr;
	private ArrayList<Item> list;
	private Payment payment;
	private String paymentID;
	private static Integer idGenerator = 0;
	
	public synchronized static String getUniqueOrderID(){
		return ((Integer) idGenerator++).toString();
	}
	
	public Order(){
		this.setOrderID(getUniqueOrderID());
	}
	
	public Customer getCustomerName() {
		return customer;
	}
	
	public void setCustomerName(Customer customer) {
		this.customer = customer;
	}
	
	public ArrayList<Item> getList() {
		return list;
	}
	
	public void setList(ArrayList<Item> list) {
		this.list = list;
	}

	public Address getBillingAddress() {
		return billingAddress;
	}

	public void setBillingAddress(Address billingAddress) {
		this.billingAddress = billingAddress;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	public Address getShippingAddress() {
		return shippingAddress;
	}

	public void setShippingAddress(Address shippingAddress) {
		this.shippingAddress = shippingAddress;
	}

	public Date getShipDate() {
		return shipDate;
	}

	public void setShipDate(Date shipDate) {
		this.shipDate = shipDate;
	}

	public Float getTotal() {
		return total;
	}

	public void setTotal(Float total) {
		this.total = total;
	}

	public Float getTax() {
		return tax;
	}

	public void setTax(Float tax) {
		this.tax = tax;
	}

	public Float getSubtotal() {
		return subtotal;
	}

	public void setSubtotal(Float subtotal) {
		this.subtotal = subtotal;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Boolean getSubmittedStatus() {
		return submittedStatus;
	}

	public void setSubmittedStatus(Boolean submittedStatus) {
		this.submittedStatus = submittedStatus;
	}

	public Float getDiscountPercent() {
		return discountPercent;
	}

	public void setDiscountPercent(Float discountPercent) {
		this.discountPercent = discountPercent;
	}

	public Float getDiscountAmount() {
		return discountAmount;
	}

	public void setDiscountAmount(Float discountAmount) {
		this.discountAmount = discountAmount;
	}

	public String getBillingAdrID() {
		return billingAdrID;
	}

	public void setBillingAdrID(String billingAdrID) {
		this.billingAdrID = billingAdrID;
	}

	public String getShippingAdrID() {
		return shippingAdrID;
	}

	public void setShippingAdrID(String shippingAdrID) {
		this.shippingAdrID = shippingAdrID;
	}

	public String getCustomerID() {
		return customerID;
	}

	public void setCustomerID(String customerID) {
		this.customerID = customerID;
	}

	public Boolean getSameBillShipAdr() {
		return sameBillShipAdr;
	}

	public void setSameBillShipAdr(Boolean sameBillShipAdr) {
		this.sameBillShipAdr = sameBillShipAdr;
	}

	public Payment getPayment() {
		return payment;
	}

	public void setPayment(Payment payment) {
		this.payment = payment;
	}

	public String getPaymentID() {
		return paymentID;
	}

	public void setPaymentID(String paymentID) {
		this.paymentID = paymentID;
	}
	
	public boolean placeOrder(ShoppingCart shoppingCart){
		return false;
	}
	
	public boolean commitOrder(){
		try{
			DatabaseAccess accessDatabase = new DatabaseAccess();
			accessDatabase.addItemToDomain(this);
		}
		catch(Exception E)
		{
			return false;
		}
		return true;
	}

	public void setOrderID(String orderID) {
		this.orderID = orderID;
	}

	public String getOrderID() {
		return orderID;
	}
	
	public static Order[] getOrder(String orderID){
		Order temp[] = null;
		DatabaseAccess accessDatabase = new DatabaseAccess();
		temp = accessDatabase.getOrder(orderID);
		return temp;
	}

}
